/*
ont-space - The ontology-based resource metadata repository
Copyright (c) 2006-2008, Information Eng. Research Unit - Univ. of Alcalá
http://www.cc.uah.es/ie
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with this library; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.ontspace.util.translator.sld2owl.owl;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.hp.hpl.jena.ontology.*;

/**
 * This class translate the method element
 *
 */
public class MethodTranslator {

    /**
     * Creates a new instance of MethodTranslator    
     * @param lnode The method node of the Dom structure
     * @param ont The ontology
     ** @param instLearningDes The learning design instance
     * @param nsName The namespace  
     */
    public MethodTranslator(Node lnode, OntModel ont,
            Individual instLearningDes, String nsName) {

        lastInstanceSLDTranslator lastInst =
                new lastInstanceSLDTranslator();

        Individual instLd =
                null;

        OntClass method =
                ont.getOntClass(nsName + "Method");
        OntClass play =
                ont.getOntClass(nsName + "Play");


        String instance =
                "method_instance_" +
                (String.valueOf(lastInst.lastInstance(method)));
        try {
            instLd =
                    ont.createIndividual(nsName + instance, method);

            if (lnode.getParentNode().getNodeName().compareTo("imsld:learning-design") ==
                    0) {
                ObjectProperty methodRef =
                        ont.getObjectProperty(nsName + "method-ref");
                instLearningDes.setPropertyValue(methodRef, instLd);

            }
        } catch (Exception e) {
        }


        NodeList children =
                lnode.getChildNodes();
        if (children != null) {
            for (int i =
                    0; i < children.getLength(); i++) {
                if (children.item(i).getNodeName().compareTo("imsld:play") == 0) {
                    PlayTranslator dp =
                            new PlayTranslator(play, children.item(i), ont,
                            instLd, nsName);
                }
                if (children.item(i).getNodeName().compareTo("imsld:complete-unit-of-learning") ==
                        0) {
                    CompleteMethodTranslator dcm =
                            new CompleteMethodTranslator(children.item(i), ont,
                            instLd, nsName);
                }
                if (children.item(i).getNodeName().compareTo("imsld:on-completion") ==
                        0) {

                    NodeList feed =
                            children.item(i).getChildNodes();
                    for (int f =
                            0; f < feed.getLength(); f++) {
                        if (feed.item(f).getNodeName().
                                compareTo("imsld:feedback-description") == 0) {
                            FeedbackDescriptionTranslator dfd =
                                    new FeedbackDescriptionTranslator(feed.item(i),
                                    ont, instLd, method, nsName);
                        }
                    }
                }
            }
        }
    }
}

